import sys

import keyring
import pyotp
import pyperclip


def main(argv):
    if argv == "-h":
        print (" -a:only google \n -pa: password + auth\n -p: only password\n")
        return
    yourname = "lingzhengxin"
    ## keychain key name
    keychain = "bilibili"
    ## keychain username
    keychainUserName = "%s@dashboard" % yourname
    keychainGAKeyName = "%s@google.auth" % yourname
    # password = keyring.set_password(keychain, keychainUserName , password)
    password = keyring.get_password(keychain, keychainUserName)
    authkey = keyring.get_password(keychain, keychainGAKeyName)

    totp = pyotp.TOTP(authkey)

    if argv == "-a":
        out = "%s" % str(totp.now())
    elif argv == "-pa":
        out = "%s%s" % (password, str(totp.now()))
    elif argv == "-p":
        out = "%s" % password
    else:
        out = "%s" % str(totp.now())
    # copy
    pyperclip.copy(str(out))


if __name__ == "__main__":
    if len(sys.argv) == 1:
        sys.argv.append("-a")
    main(sys.argv[1])
